<template>
  <el-dialog v-model="visible" title="鉴定" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()" label-width="120px">
      <el-form-item prop="appraisalDate" label="鉴定日期" >
        <el-date-picker v-model="dataForm.appraisalDate" type="datatime" placeholder="选择日期"
                        value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"> </el-date-picker>
      </el-form-item>
      <el-form-item prop="result" :rows="4"  label="鉴定结果">
        <el-select v-model="dataForm.result" placeholder="请选择">
          <el-option :value="0" label="销毁档案">销毁档案</el-option>
          <el-option :value="1" label="还原档案">还原档案</el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="remark" label="建议">
        <el-input type="textarea" :rows="4" placeholder="请输入鉴定建议" v-model="dataForm.remark"> </el-input>
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-button @click="visible = false">{{ $t("cancel") }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t("confirm") }}</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts">
  import { defineComponent, reactive } from "vue";
  import baseService from "@/service/baseService";
  import { useDebounce } from "@/utils/utils";
  import { IObject } from "@/types/interface";
  export default defineComponent({
    props:{
      idList:{
        type:Array,
        default:()=>[]
      },
    },
    setup() {
      return reactive({
        visible: false,
        tenantList: [] as IObject[],

        dataForm: {
          id: "",
          ids:[] as IObject[],
          appraisalDate: "",
          result:"",remark:""
        }
      });
    },
    computed: {
      dataRule() {
        return {
          type: [{ required: true, message: "请选择类型", trigger: "blur" }]
        };
      }
    },
    created() {
      this.dataFormSubmitHandle = useDebounce(this.dataFormSubmitHandle);
    },
    watch: {
      idList() {
        this.dataForm.ids = this.idList
      }
    },
    methods: {
      dataFormSubmitHandle() {
        this.$refs["dataFormRef"].validate((valid: boolean) => {
          if (!valid) {
            return false;
          }
          baseService.put("/archive/appraisal/authenticated", this.dataForm).then((res) => {
            if (res.code !== 0) {
              return this.$message.error(res.msg);
            }
            this.$message({
              message: this.$t("prompt.success"),
              type: "success",
              duration: 500,
              onClose: () => {
                this.visible = false;
                this.$emit("refreshDataList");
              }
            });
          });
        });
      },
    }
  });
</script>

<style lang="less" scoped>
  .el-select {
    width: 100%;
  }

</style>
